package org.chandler.ccgp.util;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.ParseException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;

public class CcgpHttpUtil {
	public static List<NameValuePair> GetParams(String startTime, String endTime){
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("searchtype", "2"));
		params.add(new BasicNameValuePair("dbselect", "bidx"));
		params.add(new BasicNameValuePair("kw", ""));
		params.add(new BasicNameValuePair("buyerName", ""));
		params.add(new BasicNameValuePair("projectId", ""));
		params.add(new BasicNameValuePair("start_time", startTime));
		params.add(new BasicNameValuePair("end_time", endTime));
		params.add(new BasicNameValuePair("timeType", "4"));
		params.add(new BasicNameValuePair("bidSort", "0"));
		params.add(new BasicNameValuePair("pinMu", "0"));
		params.add(new BasicNameValuePair("bidType", "0"));
		params.add(new BasicNameValuePair("displayZone", ""));
		params.add(new BasicNameValuePair("zoneId", ""));
		params.add(new BasicNameValuePair("agentName", ""));
		params.add(new BasicNameValuePair("page_index", "1"));
		return params;
	}
	
	/**
	 * 构造Url
	 * @param baseUrl
	 * @param params
	 * @return
	 */
	public static String genUrl(String baseUrl, List<NameValuePair> params) {
        String str = null;
		try {
			str = EntityUtils.toString(new UrlEncodedFormEntity(params));
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}  
        return new HttpGet(baseUrl).getURI().toString() + "?" + str;
	}
}
